package com.usian.sms.rabbitmq;


import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.usian.model.user.dtos.SecurityCodeDto;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * Message message, Channel channel 这两个参数都是为了消费消息队列中的信息
 */
@Component
public class CodeListener {

    @RabbitListener(queues = {"SmsQueue"})
    public void listener(@Payload String msg, Message message, Channel channel) throws IOException {
        channel.basicAck(message.getMessageProperties().getContentLength(),true);

        JSONObject jsonObject = JSONObject.parseObject(msg);

        SecurityCodeDto securityCodeDto = JSONObject.toJavaObject(jsonObject, SecurityCodeDto.class);

        System.out.println(securityCodeDto.getRandNumCode());

    }

}
